$(function () {
    $(".mylogin").on('tap', function () {
        var user = $.trim($("[name='user']").val())
        var password = $.trim($("[name='password']").val())
        if (!user) {
            mui.toast("请输入用户名")
            return;
        }
        if (!password) {
            mui.toast("请输入密码")
            return;
        }
        $.ajax({
            url: '/user/login',
            type: "POST",
            dataType: "json",
            data: {
                username: user,
                password: password
            },
            beforeSend:function(){
                $(".mylogin").html("正在登录........")
            },
            success: function (res) {
                if (res.success == true) {
                    mui.toast("登录成功")
                    setTimeout(() => {
                        $(".mylogin").html("正在登录........")
                        location.href = "user.html"
                    }, 2000);
                    $(".mylogin").html("登录")
                } else {
                    mui.toast(res.message)
                    $(".mylogin").html("登录")
                }
            }
        })
    })
})